using System.IO;
using System.Runtime.InteropServices;
using System.Text;

namespace RxjhServer
{
	internal class Ini
	{
		private const string section = "GameServer";

		private readonly string filePath;

		[DllImport("kernel32")]
		private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

		[DllImport("kernel32")]
		private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

		public Ini(string filePath)
		{
			this.filePath = filePath;
		}

		public string GetString(string key)
		{
			if (File.Exists(filePath))
			{
				int num = 1024;
				string empty = string.Empty;
				StringBuilder stringBuilder = new StringBuilder(num);
				GetPrivateProfileString("GameServer", key, empty, stringBuilder, num, filePath);
				return stringBuilder.ToString();
			}
			return string.Empty;
		}

		public bool SetString(string key, string val)
		{
			return File.Exists(filePath) && WritePrivateProfileString("GameServer", key, val, filePath) == 1;
		}
	}
}
